package org.aphelie.chronicle.ui.dialogs;

import java.util.Comparator;

import org.aphelie.chronicle.ui.ChronicleUIPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.FilteredItemsSelectionDialog;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;

public class ArcTypesSelectionDialog extends FilteredItemsSelectionDialog {
	
	private static final String DIALOG_SETTINGS= "org.aphelie.chronicle.ui.dialogs.ArcTypesSelectionDialog"; //$NON-NLS-1$
	
	@SuppressWarnings("unused")
	private String extension;
	@SuppressWarnings("unused")
	private ISelectionStatusValidator fValidator;
	private ItemsFilter filter;
	
	public ArcTypesSelectionDialog(Shell shell, boolean multi, String extension) {
		super(shell, multi);
		this.extension = extension;
	}

	@Override
	protected Control createExtendedContentArea(Composite parent) {
		Control addition= null;

		/*if (extension != null) {

			addition= extension.createContentArea(parent);
			if (addition != null) {
				GridData gd= new GridData(GridData.FILL_HORIZONTAL);
				gd.horizontalSpan= 2;
				addition.setLayoutData(gd);

			}

			extension.initialize(this);
		}
		*/
		return addition;
	}

	@Override
	protected IDialogSettings getDialogSettings() {
		IDialogSettings settings = ChronicleUIPlugin.getDefault().getDialogSettings().getSection(DIALOG_SETTINGS);
		if (settings == null) {
			settings = ChronicleUIPlugin.getDefault().getDialogSettings().addNewSection(DIALOG_SETTINGS);
		}
		return settings;
	}

	@Override
	protected IStatus validateItem(Object item) {
		if (item == null)
			return new Status(IStatus.ERROR, ChronicleUIPlugin.PLUGIN_ID, IStatus.ERROR, "", null); //$NON-NLS-1$

		/*if (fValidator != null) {
			/*IType type= ((TypeNameMatch) item).getType();
			if (!type.exists()) {
				String qualifiedName= TypeNameMatchLabelProvider.getText((TypeNameMatch) item, TypeNameMatchLabelProvider.SHOW_FULLYQUALIFIED);
				return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.ERROR, Messages.format(JavaUIMessages.FilteredTypesSelectionDialog_error_type_doesnot_exist, qualifiedName), null);
			}
			Object[] elements= { type };
			return fValidator.validate(elements);
			
		} else */
			return Status.OK_STATUS;
	}

	@Override
	protected ItemsFilter createFilter() {
		filter = new ArcItemFilter();
		return filter;
	}

	@Override
	protected Comparator<?> getItemsComparator() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected void fillContentProvider(AbstractContentProvider contentProvider,
			ItemsFilter itemsFilter, IProgressMonitor progressMonitor)
			throws CoreException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public String getElementName(Object item) {
		// TODO Auto-generated method stub
		return null;
	}

	private class ArcItemFilter extends ItemsFilter {

		@Override
		public boolean matchItem(Object item) {
			return true;
		}

		@Override
		public boolean isConsistentItem(Object item) {
			return true;
		}
		
	}
	
	
	
}
